home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ATalkSampleUtils.c
-
- Contains:
-
- Written by:
-
- Copyright: Copyright © 1993-1999 by Apple Computer, Inc., All Rights Reserved.
-
- You may incorporate this Apple sample source code into your program(s) without
- restriction. This Apple sample source code has been provided "AS IS" and the
- responsibility for its operation is yours. You are not permitted to redistribute
- this Apple sample source code as "Apple sample source code" after having made
- changes. If you're going to re-distribute the source, we require that you make
- it clear in the source that the code was descended from Apple sample source
- code, but that you've made changes.
-
- Change History (most recent first):
- 7/22/1999 Karl Groethe Updated for Metrowerks Codewarror Pro 2.1
-
-
- */
-
- #ifndef __ATALKSAMPLEUTILS__
- #include "ATalkSampleUtils.h"
- #endif
- #ifndef __OPENTPTAPPLETALK__
- #include "OpenTptAppleTalk.h"
- #endif
- #include <Menus.h>
- #include <Devices.h>
- #include <Events.h>
- #ifndef __STDIO__
- #include <stdio.h>
- #endif
-
- /*******************************************************************************
- ** ShowEndpointInfo
- **
- ********************************************************************************/
-
- static void ShowSize(char* format, SInt32 size)
- {
- if ( size == T_INFINITE )
- fprintf(stderr, "%sT_INFINITE\n", format);
- else if ( size == T_INVALID )
- fprintf(stderr, "%sT_INVALID\n", format);
- else
- fprintf(stderr, "%s%ld\n", format, size);
- }
-
- void ShowEndpointInfo(EndpointRef ep)
- {
- TEndpointInfo info;
- OSStatus err;
- SInt32 flags;
- char* type;
- Boolean ndComma;
-
- err = OTGetEndpointInfo(ep, &info);
- fprintf(stderr, " TEndpointInfo:\n");
- if ( err != kOTNoError )
- {
- fprintf(stderr, " ERROR! = %d\n", err);
- }
- else
- {
- ShowSize(" addr = ", info.addr);
- ShowSize(" options = ", info.options);
- ShowSize(" tsdu = ", info.tsdu);
- ShowSize(" etsdu = ", info.etsdu);
- ShowSize(" connect = ", info.connect);
- ShowSize(" discon = ", info.discon);
-
- fprintf(stderr, " servtype = ");
- switch ( info.servtype )
- {
- case T_COTS: type = "T_COTS"; break;
- case T_COTS_ORD: type = "T_COTS_ORD"; break;
- case T_CLTS: type = "T_CLTS"; break;
- case T_TRANS: type = "T_TRANS"; break;
- case T_TRANS_ORD: type = "T_TRANS_ORD"; break;
- case T_TRANS_CLTS: type = "T_TRANS_CLTS"; break;
- default: type = NULL;
- }
- if ( type != NULL )
- fprintf(stderr, "%s\n", type);
- else
- fprintf(stderr, "%lu\n", info.servtype);
-
- flags = info.flags;
- fprintf(stderr, " flags = ", info.flags);
- ndComma = false;
- if ( flags & T_SENDZERO )
- {
- flags &= ~T_SENDZERO;
- fprintf(stderr, "T_SENDZERO");
- ndComma = true;
- }
- if ( flags & T_XPG4_1 )
- {
- flags &= ~T_XPG4_1;
- if ( ndComma )
- fprintf(stderr, ", ");
- ndComma = true;
- fprintf(stderr, "T_XPG4_1");
- }
- if ( flags & T_CAN_RESOLVE_ADDR )
- {
- flags &= ~T_CAN_RESOLVE_ADDR;
- if ( ndComma )
- fprintf(stderr, ", ");
- ndComma = true;
- fprintf(stderr, "T_CAN_RESOLVE_ADDR");
- }
- if ( flags & T_CAN_SUPPLY_MIB )
- {
- flags &= ~T_CAN_SUPPLY_MIB;
- if ( ndComma )
- fprintf(stderr, ", ");
- ndComma = true;
- fprintf(stderr, "T_CAN_SUPPLY_MIB");
- }
- if ( flags != 0 )
- {
- if ( ndComma )
- fprintf(stderr, ", ");
- fprintf(stderr, "%08lX", flags);
-
- }
- fprintf(stderr, "\n");
- }
- }
-
- /*******************************************************************************
- ** ShowEndpointState
- ********************************************************************************/
-
- void ShowEndpointState(EndpointRef ep, char* prefixString)
- {
- char* strPtr;
- OTResult state;
-
- state = OTGetEndpointState(ep);
-
- fprintf(stderr, "%sState = %d, ", prefixString, state);
- switch ( state )
- {
- case T_UNINIT:
- strPtr = "T_UNINIT";
- break;
- case T_UNBND:
- strPtr = "T_UNBND";
- break;
- case T_IDLE:
- strPtr = "T_IDLE";
- break;
- case T_OUTCON:
- strPtr = "T_OUTCON";
- break;
- case T_INCON:
- strPtr = "T_INCON";
- break;
- case T_DATAXFER:
- strPtr = "T_DATAXFER";
- break;
- case T_OUTREL:
- strPtr = "T_OUTREL";
- break;
- case T_INREL:
- strPtr = "T_INREL";
- break;
- // case T_INFLUX:
- // strPtr = "T_INFLUX";
- // break;
- default:
- strPtr = "Unknown";
- }
- fprintf(stderr,"%s\n", strPtr);
- }
-
- /*******************************************************************************
- ** ShowFullEndpointData
- **
- ********************************************************************************/
-
- void ShowFullEndpointData(EndpointRef ep)
- {
- fprintf(stderr, "FULL ENDPOINT INFO FOR ENDPOINT AT %08lX\n", ep);
-
- fprintf(stderr, " Mode = %s\n", (OTIsSynchronous(ep) ? "Synchronous" : "Asynchronous"));
-
- ShowEndpointState(ep, " ");
-
- fprintf(stderr, " Look() = %d\n", OTLook(ep));
-
- ShowEndpointInfo(ep);
-
- fprintf(stderr, "");
- }
-
- /*******************************************************************************
- ** ShowDDPAddress -- print out an AppleTalk DDP address
- ********************************************************************************/
-
- void ShowDDPAddress(DDPAddress* addr)
- {
- if (addr->fAddressType == AF_ATALK_DDP ||
- addr->fAddressType == AF_ATALK_DDPNBP)
- {
- fprintf(stderr, "Net $%04X, Node $%02X, Socket $%02X, Type $%02X",
- addr->fNetwork, addr->fNodeID, addr->fSocket, addr->fDDPType);
- }
- else
- fprintf(stderr, "Not DDP Addr!");
- }
-
-